import time


# 消费者
def consumer():
    cnt = yield
    while True:
        if cnt <= 0:
            cnt = yield cnt
        cnt -= 1
        time.sleep(1)
        print("consumer consume 1 cnt >> cnt=", cnt)


# 生产者
def producer(cnt):
    gen = consumer()
    next(gen)
    gen.send(cnt)
    while True:
        cnt += 5
        print("producer product 5 cnt >>>>> cnt=", cnt)
        current = int(time.time())
        if current % 7 == 0:
            cnt = gen.send(cnt)
        else:
            time.sleep(1)


if __name__ == '__main__':
    producer(0)